import ctypes
from python_app.railsim.libapi import (
    ELECTRIC_MOTOR_TYPE,
    RAILROAD_CAR_TYPE,
    ElectricLocomotive,
    ElectricMotorProperty,
    RailroadCarProperty,
    RailroadWagon,
    Track,
    Train,
)


def create_default_freight_train():
    motorProperty = ElectricMotorProperty.create_value(
        "YJ85-A".encode("utf8"),
        ELECTRIC_MOTOR_TYPE.THREE_PHASED_ASYNC,
        1250,
        11852,
        2662,
        0.92,
        4.85,
    )

    loco_ptr, loco = ElectricLocomotive.create(5, 25, 25 * 6, 1.20, 6, motorProperty)
    assert loco_ptr is not None
    assert loco.motorNum == 6
    assert loco.motorProperty.name == b"YJ85-A"

    wagons = []
    car_property = RailroadCarProperty.create(
        "N6".encode("utf-8"),
        RAILROAD_CAR_TYPE.RAILROAD_CAR_TYPE_FLATCAR,
        12.5,
        100,
        21.5,
        60,
    )
    for i in range(60):
        wagon = RailroadWagon.create(car_property)
        print(hex(ctypes.addressof(wagon.property.contents)))
        wagon.load = 50.0
        wagon.id = i
        wagons.append(wagon)

    train = Train.create([loco], wagons)

    return train
